package com.google.code.virtualhockey.vhx.shared.error;

import com.google.code.virtualhockey.vhx.shared.rpc.ICommand;

/**
 * Indicates that a command could not be processed, because no appropriate
 * command handler was found.
 */
public class WebNoCommandHandlerException extends WebServerException
{
  private ICommand<?> m_commandNotHandled;

  /** Argumentless default constructor for GWT/RPC. */
  protected WebNoCommandHandlerException()
  {
  }

  /**
   * Creates a new WebNoCommandHandlerException.
   *
   * @param command the command which could not be handled
   */
  public WebNoCommandHandlerException( ICommand<?> command )
  {
    super( "Failed to find command handler for command implementation '" + command.getClass().getName() + "'"
        + ( command.getDispatchInfo() != null ? " and dispatch info '" + command.getDispatchInfo() + "'" : "" ) + "." );

    m_commandNotHandled = command;
  }

  /**
   * Returns the command that was not handled because no appropriate handler was
   * found.
   */
  public ICommand<?> getUnhandledCommand()
  {
    return m_commandNotHandled;
  }
}
